package main

import (
	"fmt"
	"io"
	"os"
)

type Animal interface {
	Sleep()
	Eat()
}

type Dog struct {
	name string
	color string
}

type Cat struct {
	name string
	color string
}

func (d *Dog) setName(name string) {
	d.name = name
}
func (d *Dog) setColor(color string) {
	d.color = color
}

func (c *Cat) Sleep() {
	fmt.Println("cat sleep")
}

func (c *Cat) Eat() {
	fmt.Println("cat eat")
}

func (d *Dog) Eat()  {
	fmt.Println("dog eat")
}
func (d *Dog) Sleep()  {
	fmt.Println("dog sleep")
}

func showAnimal(animal Animal) {
	animal.Eat()
}

func main() {

	var animal Animal
	animal = &Cat{}
	animal.Sleep()
	animal = &Dog{}
	animal.Sleep()
	showAnimal(&Cat{})


	d := Dog{}
	d.setName("aaa")
	d.setColor("black")
	showAnimal(&d)
	fmt.Println(d)

	//m := make(map[string]Dog)
	//
	//s := []int{}
	//
	//a := [3]int{}

	file, err := os.OpenFile("file", os.O_RDWR, 0)
	if err != nil {
		fmt.Println(err)
	}
	by := []byte{}
	n, err := file.Read(by)
	if err == io.EOF {
		fmt.Println(err)
	}
	fmt.Println("读取行数:",n)

	//var r io.Reader
	//r.Read(file)
}
